package shuati.shuzimali;

import java.util.Scanner;

/**
 * @author : LdLtd
 * @Date : 2024/4/22
 * @Description:
 */
public class c2413 {
    //已知，纽时间比北京时间慢12小时，请根据用户输入的北京时间输出相应的纽约时间，
    // 若用户输入错误的月份或日期等信息则将其顺加、
    // 如用户输入2021 13 32 14 43 54则生成北京时间为:2022-02-01 14:43:54纽约时间为:2022-02-01 02:43:54
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int year = in.nextInt();
        int month = in.nextInt();
        int day = in.nextInt();
        int hour = in.nextInt();
        int minute = in.nextInt();
        int second = in.nextInt();
        // 定义每个月的天数，考虑闰年的情况
        int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if (second > 60) {
            minute += second / 60;
            second = second % 60;
        }
        if (minute > 60) {
            hour += minute / 60;
            minute = minute % 60;
        }
        if (hour > 24) {
            day += hour / 24;
            hour = hour % 24;
        }
        if (day > 31) {
            month += day / 31;
            day = day % 31;
        }
        // 判断输入的日期是否合法
        if (month > 12) {
            year += month / 12;
            month = month % 12;
        }
        // 判断是否是闰年
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            daysInMonth[1] = 29;
        }     // 判断输入的月份是否合法
        if (day > daysInMonth[month - 1]) {
            month += day / daysInMonth[month - 1];
            day = day % daysInMonth[month - 1];
        }

        if (month < 0 || year < 1 || day < 0 || hour < 0 || second < 0) {
                System.out.println("您输入的数据不合理！");
            }

        String beijingTime = String.format("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
            System.out.println("北京时间为:" + beijingTime);
            hour -= 12;
            if (hour < 0) {
                day -= 1;
                hour += 24;
            }
            if (day < 1) {
                month -= 1;
                if (month < 1) {
                    year -= 1;
                    month = 12;
                }
                day = daysInMonth[month - 1];
            }
        String newYorkTime = String.format("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
        System.out.println("纽约时间为:" + newYorkTime);

    }
}
